package com.example.myapplication_2

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import java.time.format.TextStyle



class MainActivity : AppCompatActivity() {
    var count = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
//        区域1
        val button = findViewById<Button>(R.id.btnAddTextView)
        val linearLayout = findViewById<LinearLayout>(R.id.containerTextViews)
        button.setOnClickListener {
            count++
            val textView = TextView(this)
            textView.text = "TextView Count $count"
            textView.textSize = 40f
            linearLayout.addView(textView)
        }
//        区域2
        val expert = ProgramExpert()

        val button2 = findViewById<Button>(R.id.btnQuery)
        val spinner = findViewById<Spinner>(R.id.spinner)
        val textView2 = findViewById<TextView>(R.id.tvAdviceResult)
        button2.setOnClickListener {
//            val selectedFeature = spinner.selectedItem.toString()
//            textView2.text = selectedFeature
            textView2.text = expert.getLangue(spinner.selectedItem.toString())
        }
    }
}